// 用户权限
module.exports = app => {
    const DataTypes = app.Sequelize;
    const SysUserRole = app.model.define('SysUserRole', {
        id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
        },
        sys_user_id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
        },
        role_id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
        },
        created_by: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
        },
        is_delete: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '是否删除，0->存在，1->删除'
        },
    }, {
        tableName: 'sys_user_role'
    });
    SysUserRole.associate = function () {
        SysUserRole.belongsTo(app.model.SysRole, {
            as: 'Role',
            foreignKey: 'role_id',
            targetKey: "id",
            constraints: false
        });

        SysUserRole.belongsTo(app.model.SysUser, {
            as: 'User',
            foreignKey: 'sys_user_id',
            targetKey: "id",
            constraints: false
        });

    };
    return SysUserRole;
};
